package com.ruoyi.web.controller.customerapply;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.customerapply.domain.CrmCustomerApply;
import com.ruoyi.customerapply.service.ICrmCustomerApplyService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 客户申请Controller
 * 
 * @author hct
 * @date 2022-02-16
 */
@RestController
@RequestMapping("/customerapply/customerapply")
public class CrmCustomerApplyController extends BaseController
{
    @Autowired
    private ICrmCustomerApplyService crmCustomerApplyService;

    /**
     * 查询客户申请列表
     */
    @PreAuthorize("@ss.hasPermi('customerapply:customerapply:list')")
    @GetMapping("/list")
    public TableDataInfo list(CrmCustomerApply crmCustomerApply)
    {
        startPage();
        crmCustomerApply.setStatus(0);
        List<CrmCustomerApply> list = crmCustomerApplyService.selectCrmCustomerApplyList(crmCustomerApply);
        return getDataTable(list);
    }

    /**
     * 导出客户申请列表
     */
    @PreAuthorize("@ss.hasPermi('customerapply:customerapply:export')")
    @Log(title = "客户申请", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CrmCustomerApply crmCustomerApply)
    {
        List<CrmCustomerApply> list = crmCustomerApplyService.selectCrmCustomerApplyList(crmCustomerApply);
        ExcelUtil<CrmCustomerApply> util = new ExcelUtil<CrmCustomerApply>(CrmCustomerApply.class);
        util.exportExcel(response, list, "客户申请数据");
    }

    /**
     * 获取客户申请详细信息
     */
    @PreAuthorize("@ss.hasPermi('customerapply:customerapply:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(crmCustomerApplyService.selectCrmCustomerApplyById(id));
    }

    /**
     * 新增客户申请
     */
    @PreAuthorize("@ss.hasPermi('customerapply:customerapply:add')")
    @Log(title = "客户申请", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    public AjaxResult add(@RequestBody CrmCustomerApply crmCustomerApply)
    {
        crmCustomerApply.setStatus(0);
        return toAjax(crmCustomerApplyService.insertCrmCustomerApply(crmCustomerApply));
    }

    /**
     * 修改客户申请
     */
    @PreAuthorize("@ss.hasPermi('customerapply:customerapply:edit')")
    @Log(title = "客户申请", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CrmCustomerApply crmCustomerApply)
    {
        return toAjax(crmCustomerApplyService.updateCrmCustomerApply(crmCustomerApply));
    }

    /**
     * 同意或者拒绝
     */
    @PreAuthorize("@ss.hasPermi('customerapply:customerapply:agree')")
    @Log(title = "操作客户申请", businessType = BusinessType.UPDATE)
    @PostMapping("/agree")
    public AjaxResult agree(@RequestBody CrmCustomerApply crmCustomerApply)
    {
        return toAjax(crmCustomerApplyService.agreeCrmCustomerApply(crmCustomerApply));
    }

    /**
     * 删除客户申请
     */
    @PreAuthorize("@ss.hasPermi('customerapply:customerapply:remove')")
    @Log(title = "客户申请", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(crmCustomerApplyService.deleteCrmCustomerApplyByIds(ids));
    }
}
